﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="../system/index/meta.jsp" %>
    <title>新闻管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 新闻管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray"> <span class="l"> <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>  </span> <span class="r">共有数据：<strong>${count}</strong> 条</span> </div>
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="8">新闻管理</th>
			</tr>
			<tr class="text-c">
				<th width="50"><input type="checkbox" value="" name=""></th>
				<th width="50">编号</th>
				<th width="150">新闻标题</th>
				<th width="100">作者</th>
				<th width="100">状态</th>
				<th width="300" style="width:300px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;">内容</th>
				<th width="150">发布时间</th>
				<th width="150">操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${news}" var="news" varStatus="status">
				<tr class="text-c">
				<td><input type="checkbox" value="" name=""></td>
				<td>${status.count}</td>
				<td>${news.title}</td>
				<td>${news.author}</td>
				<td>${news.state}</td>
				<td style="width:300px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;">${news.content}</td>
				<td><fmt:formatDate value="${news.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td class="f-14">
				    <a title="编辑" href="javascript:;" onclick="editNews('新闻编辑','${pageContext.request.contextPath}/newsServlet?method=edit&id=${news.id}','900','680')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> 
				    <a title="删除" href="javascript:;" onclick="deleteNews(this, '${news.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
			    </td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
<%@ include file="../system/index/footer.jsp" %>
<script type="text/javascript">
/*管理员-新闻-添加*/
function addNews(title,url,w,h){
	layer_show(title,url,w,h);
}
/*编辑*/
function editNews(title,url,w,h){
	var index = layer.open({
        type: 2,
        area: [w+'px', h +'px'],
        fix: false, //不固定
        maxmin: true,
        shade:0.4,
        title: title,
        content: url
    });
	layer.full(index);
}
/*新闻-删除*/
function deleteNews(obj,id){
	var pageContext = "${pageContext.request.contextPath}";
	layer.confirm("新闻删除须谨慎，确认要删除吗？",function(index){
		$.ajax({
			type: "POST",
			url: pageContext+"/newsServlet?method=del",
			dataType: "json",
			data:{"id": id},
			success: function(req){
				//请求成功时处理
                if(req.success) {
                    layer.msg(req.msg, {
                          icon: 6,
                          offset: '100px',
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                    	$(obj).parents("tr").remove();
                    });
                } else {
                    layer.msg(req.msg, {
                          icon: 5,
                          offset: '100px',
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }); 
                }
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script>
</body>
</html>